package com.socialuni.jimei.controller;

import com.socialuni.api.model.QO.talk.SocialUserTalkQueryQO;
import com.socialuni.api.model.RO.talk.SocialTalkRO;
import com.socialuni.api.model.ResultRO;
import com.socialuni.jimei.model.UserTalkQueryVO;
import com.socialuni.sdk.api.TalkAPI;
import com.socialuni.sdk.model.DO.user.AccountDO;
import com.socialuni.sdk.utils.model.SocialUserAccountUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("talk")
public class TalkController {
    @Resource
    TalkAPI talkApi;

    @PostMapping("queryUserTalks")
    ResultRO<List<SocialTalkRO>> queryUserTalks(@RequestBody @Valid @NotNull UserTalkQueryVO queryVO) {
        AccountDO accountDO = SocialUserAccountUtil.getUserSocialAccount(queryVO.getUserId());
        String centerUserId = accountDO.getUnionId();

        SocialUserTalkQueryQO socialUserTalkQueryQO = new SocialUserTalkQueryQO(centerUserId, queryVO.getTalkIds());

        return talkApi.queryUserTalks(socialUserTalkQueryQO);
    }
}
